﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GestionRecaudos
{
    public partial class FrmAdministrarBackUps : Form
    {
        public FrmAdministrarBackUps()
        {
            InitializeComponent();
        }

        private void FrmAdministrarBackUps_Load(object sender, EventArgs e)
        {
            this.directorioTextBox.Text=Utils.get().getValorParametro("DirectorioBackUps");
        }

        private void EjecutarButton_Click(object sender, EventArgs e)
        {
            try
            {
                System.Data.SqlClient.SqlConnectionStringBuilder builder = new System.Data.SqlClient.SqlConnectionStringBuilder();
                builder.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings[Utils.get().getValorParametro("SeccionAppConfigGestionRecaudosConnectionString")].ConnectionString;
                //string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings[Utils.get().getValorParametro("SeccionAppConfigGestionRecaudosConnectionString")].ConnectionString;
                using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(builder.ConnectionString))
                {
                    conn.Open();
                    System.Data.SqlClient.SqlCommand command = conn.CreateCommand();
                    command.CommandType = CommandType.StoredProcedure;
                    command.CommandText = "[spBackupBaseDatos]";
                    command.Parameters.Add(new System.Data.SqlClient.SqlParameter("@DirectorioDestino", this.directorioTextBox.Text));
                    command.Parameters.Add(new System.Data.SqlClient.SqlParameter("@NombreBaseDatos", builder.InitialCatalog));
                    command.ExecuteReader();
                    conn.Close();
                }
                MessageBox.Show("La Copia de Seguridad se Realizo Satisfactoriamente!");
                this.Close();
            }
            catch (Exception ex)
            {
                MessageException.show(ex);
            }
        }
    }
}
